﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>管理员列表</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
        <link href="/style/admin/style/adminStyle.css" rel="stylesheet" type="text/css" />
        <script src="/style/admin/js/jquery.js"></script>
        <script src="/style/admin/js/public.js"></script>
        <style>
            .pagination{
                padding-top: 10px;
            } 
            .pagination li{
                float:left; 
                color: #333;
                border: 1px solid #ddd;
                background-color: #f7f7f7;
                background-repeat: repeat-x;
                height: 36px;
                line-height: 36px;
                padding: 0 14px;
                margin-right: 5px;
                font-size: 14px;
            }
            .pagination .active{
                background: none;
            }
        </style>
    </head>
    <body>
        <div class="wrap">
            <div class="page-title">
                <span class="modular fl"><i class="user"></i><em>管理员列表</em></span>
                <span class="modular fr"><a href="admin/create" class="pt-link-btn">+添加管理员</a></span>
            </div>
            <table class="list-style Interlaced">
                <tr>
                    <th>序号</th> 
                    <th>账号</th> 
                    <th>添加时间</th>
                    <th>状态</th>
                    <th>最后登陆时间</th>
                    <th>操作</th>
                </tr>
                @foreach($data as $value)
                <tr>
                    <td class="center">{{$value->id}}</td>
                    <td class="center">{{$value->name}}</td>
                    <td class="center">{{date('Y-m-d H:m:s',$value->time)}}</td>
                    @if($value->status==0)
                    <td class="center"><button class="n_btn" onclick="EditStatus(this,{{$value->id}},1)">正常</button></td>
                    @else
                    <td class="center"><button class="d_btn" onclick="EditStatus(this,{{$value->id}},0)">禁用</button></td>
                    @endif 
                    <td class="center">{{$value->lasttime}}</td>
                    <td class="center">
                        <a href="admin/{{$value->id}}/edit"><img src="/style/admin/images/icon_edit.gif"/></a>
                        <a href="javascript::;" onclick="del({{$value->id}})"><img src="/style/admin/images/icon_drop.gif"/></a>
                    </td>
                </tr>
                @endforeach       
            </table>
            {{ $data->links() }} 
        </div>
    </body>
    <script>
        //anax删除管理员
          function del(id){ 
              $.post('/admin/admin/'+id,{'_token':"{{csrf_token()}}","_method":'delete'},function(data){
                   if(data==1){
                       window.location.reload();
                   }else{
                       alert("删除失败");
                   }
              })
          }
        //ajax修改管理员状态
            function EditStatus(obj,id,status){
                if(status==1){
                  $.post('/admin/admin/AjaxStatus',{'id':id,'_token':"{{csrf_token()}}",'status':status},function(data){
                      if(data==1){
                          $(obj).parent().html('<button class="d_btn" onclick="EditStatus(this,'+id+',0)">禁用</button>')
                      }else{
                          alert("修改失败");
                      }
                  })
              }else if(status==0){
                  $.post('/admin/admin/AjaxStatus',{'id':id,'_token':"{{csrf_token()}}",'status':status},function(data){
                      if(data==1){
                          $(obj).parent().html('<button class="n_btn" onclick="EditStatus(this,'+id+',1)">正常</button>')
                      }else{
                          alert("修改失败");
                      }
                  })
              }
            }
    </script>
</html>